package com.su.ou.yang;

import java.sql.ClientInfoStatus;
import java.util.ArrayList;
import java.util.Arrays;

public class Test6 {
    public static void main(String[] args) {
        int[] nums1={1,2,3,4};
        int[] nums2={2,3,4,5,6};
        ArrayList<Integer> list = solve(nums1, nums2);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

    }
    public static ArrayList<Integer> solve(int[] nums1,int[] nums2){
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        ArrayList<Integer> list = new ArrayList<Integer>();
        int left1=0;
        int left2=0;
        int right1=nums1.length;
        int right2=nums2.length;
        while(left1<right1&&left2<right2){
            if(nums1[left1]==nums2[left2]){
                list.add(nums1[left1]);
                left1++;
                left2++;
            }
           else if(nums1[left1]<nums2[left2]) {
                left1++;
            }else{
                left2++;
            }
        }
       return list;
    }

}
